package dreampack.dataModify;

import java.sql.*;
//import java.util.*;

import dreampack.*;
import dreampack.dataType.*;

public class EmailModify {
	public EmailModify() { }
	
	public static boolean sendEmail(
			DreamDB dreamDb, UserType receiveUser, String title,  
			String adjunct, String content, UserType sendUser) throws Exception {
		Connection con = null;
		PreparedStatement prepStmt = null;
		boolean bRet = true;
		
		if (adjunct.equals(""))
			adjunct = null;
		
		try {
			con = dreamDb.getConnection();
			String insertStatement = "insert into t_email values(id, ?, ?, ?, ?, ?, now(), ?)";
			prepStmt = con.prepareStatement(insertStatement);
			prepStmt.setString(1, title);
			prepStmt.setString(2, adjunct);
			prepStmt.setString(3, content);
			prepStmt.setInt(4, sendUser.getId());
			prepStmt.setInt(5, receiveUser.getId());
			prepStmt.setBoolean(6, true);
			prepStmt.executeUpdate();
		}catch (Exception e){
			bRet = false;
		}finally {
			dreamDb.closePrepStmt(prepStmt);
			dreamDb.closeConnection(con);
		}
		
		return bRet;
	}
	
	public static boolean saveEmail(DreamDB dreamDb) throws Exception {
		return false;
	}
	
	public static boolean readEmail(DreamDB dreamDb) throws Exception {
		return false;
	}
	
	public static boolean deleteEmail(DreamDB dreamDb) throws Exception {
		return false;
	}
}
